package com.exam.api.modules.exampaper.controller;

import cn.hutool.core.util.URLUtil;
import com.exam.api.common.cardRecognition.CardRecognitionResult;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.exampaper.dto.ExamRecognitionDto;
import com.exam.api.modules.exampaper.dto.PatchAnswerItemDto;
import com.exam.api.modules.exampaper.service.TblExamPaperService;
import com.exam.api.modules.exampaper.vo.ExamPaperVO;
import com.exam.api.modules.exampaper.vo.PageExamPaperVO;
import com.exam.api.modules.exampaper.vo.UserReviewAnswerVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 试卷主表相关接口
 */
@Tag(name = "(管理端) 试卷主表相关接口", description = "(管理端) 试卷主表相关接口")
@RestController
@RequestMapping("/examPaper")
@TinyResponse
public class TblExamPaperController {

    @Resource
    private TblExamPaperService tblExamPaperService;

    @Operation(summary = "获取我的试卷列表", description = "查询列表")
    @PostMapping("/userExamPaperList")
    public List<PageExamPaperVO> userExamPaperList() {
        return tblExamPaperService.userExamPaperList();
    }

    @Operation(summary = "交卷", description = "交卷")
    @PostMapping("/patchAnswer/{id}")
    public Long patchAnswer(@PathVariable("id") Long id,@RequestBody List<PatchAnswerItemDto> answerItemList) {
        return tblExamPaperService.patchAnswer(id,answerItemList);
    }
    @Operation(summary = "识别答题卡", description = "交卷")
    @PostMapping("/recognition")
    public CardRecognitionResult recognition(@RequestBody ExamRecognitionDto dto) {
        return tblExamPaperService.recognition(dto.getId(),URLUtil.decode(dto.getUrl()));
    }

    @Operation(summary = "根据ID获取试卷", description = "根据ID获取试卷")
    @PostMapping("/{id}")
    public ExamPaperVO getTblExamPaper(@PathVariable("id") Long id) {
        return tblExamPaperService.getExamPaperVO(id);
    }

    @Operation(summary = "根据ID获取评分结果", description = "")
    @PostMapping("/reviewAnswer/{id}")
    public UserReviewAnswerVO getReviewAnswer(@PathVariable("id") Long id) {
        return tblExamPaperService.getReviewAnswer(id);
    }
}